home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 2 / Gold Medal Software Volume 2 (Gold Medal) (1994).iso / os2 / cenvi2.arj / RUNTIME.CMD < prev    next >
OS/2 REXX Batch file  |  1993-09-26  |  2KB  |  64 lines

  1. @echo off
  2. REM *************************************************************************
  3. REM *** RunTime.cmd - Execute commands at supplied time                   ***
  4. REM *************************************************************************
  5.  
  6. ECHO Command: %2 %3 %4 %5 %6 %7 %8 %9
  7. CEnvi %0.cmd %1
  8. GOTO CENVI_EXIT
  9.  
  10. // define TIME_CHECK_DELAY for how long to delay in between each time
  11. // checking if the RunTime has come yet.  This time is in milliseconds so
  12. // 1000 is 1 second. This time is not exact so setting to 60000 (60 seconds)
  13. // might miss an entire minute. Less then 100 would probably take up more
  14. // processor time than you want, but still not very much
  15. #define  TIME_CHECK_DELAY  5000  // check every 5 seconds
  16.  
  17. main(argc,argv)
  18. {
  19.    if ( argc < 2  ||  2 != sscanf(argv[1],"%d:%d",RunHour,RunMinute)
  20.      || RunHour < 0  ||  23 < RunHour
  21.      || RunMinute < 0  ||  59 < RunMinute ) {
  22.       Instructions();
  23.    } else {
  24.       printf("Scheduled time: %02d:%02d:00\n",RunHour,RunMinute);
  25.       // Loop here forever until RunHour:RunMinute comes along, then exit
  26.       DisplayedSecond = -1; // force current time to print
  27.       do {
  28.          GetCurrentTime(CurrentHour,CurrentMinute,CurrentSecond);
  29.          if ( CurrentSecond != DisplayedSecond )
  30.             printf("\rCurrent Time:   %02d:%02d:%02d",
  31.                    CurrentHour,CurrentMinute,DisplayedSecond=CurrentSecond);
  32.          suspend(TIME_CHECK_DELAY);
  33.       } while ( CurrentHour != RunHour  ||  CurrentMinute != RunMinute );
  34.       printf("\n");
  35.    }
  36. }
  37.  
  38. GetCurrentTime(hour,minute,second)
  39. {
  40.    now = localtime(time());
  41.    hour = now.tm_hour;
  42.    minute = now.tm_min;
  43.    second = now.tm_sec;
  44. }
  45.  
  46. Instructions()
  47. {
  48.    printf("\n");
  49.    printf("RunTime - Perform a command, with up to 7 parameters, at a specified time.\n");
  50.    printf("\n");
  51.    printf("SYNTAX: RunTime <hour>:<minute> [Command] [parm1] [parm2] [etc...]\n");
  52.    printf("\n");
  53.    printf("Where: hour   - hour of day (in 24-hour format) to run command; range 0 - 23\n");
  54.    printf("       minute - minute of hour to run command: range 0 - 59\n");
  55.    printf("\n");
  56.    printf("Examples: RunTime 14:30 chkdsk c: /f   - run chkdsk at 2:30 PM\n");
  57.    printf("          RunTime 0:00                 - pause computer until midnight\n");
  58.    printf("\n");
  59. }
  60.  
  61. :CENVI_EXIT
  62. ECHO %2 %3 %4 %5 %6 %7 %8 %9
  63. %2 %3 %4 %5 %6 %7 %8 %9
  64.